if (self = [super init]) vs. if ((self = [super init]))

Posted by JOM on Stack Overflow See other posts from Stack Overflow or by JOM
Published on 2010-06-17T05:57:32Z Indexed on 2010/06/17 6:03 UTC
Read the original article Hit count: 155

Was just doing a code review and started to wonder:

I thought if (self = [super init]) checks whether assigning return value of [super init] to variable self was successful or not (value of operation). Thus (self = nil) would actually be TRUE.

I thought if ((self = [super init])) checks what is the value of self after assignment (value of variable). Thus ((self = nil)) would be FALSE.

Which one is the correct way to use when initializing your own classes? Apple documentation uses the former one (for example here), which style I'm actually using now.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c